package com.admin.action.library_page_action;

import com.admin.Action;
import com.admin.dto.BookTopListBean;
import com.admin.service.libraryservice.LibraryPage;
import com.admin.service.libraryservice.LibraryPageServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 图书借阅的饼状图
 */
public class BookTopAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        LibraryPage libraryPage = new LibraryPageServiceImpl();
        List<BookTopListBean> list=libraryPage.BOOK_TOP_LIST_BEAN_LIST();
//        for(BookTopListBean kj:list){
//            System.out.println(kj.getBookName());
//            System.out.println(kj.getBookSales());
//        }

        Gson gson = new Gson();
        String jsonStr =   gson.toJson(list);
        out.print(jsonStr);
    }
}
